package com.example.socialwebserver.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.socialwebserver.mapper.AdminMapper;
import com.example.socialwebserver.pojo.AdminDAO;
import com.example.socialwebserver.pojo.LoginDTO;
import com.example.socialwebserver.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    AdminMapper adminMapper;
    @Override
    public List<AdminDAO> SelectAll() {
        List<AdminDAO> adminDAOS = adminMapper.selectList(null);
        return adminDAOS;
    }

    @Override
    public Integer adminLogin(LoginDTO loginDTO) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("admin_name",loginDTO.getUserName());
        queryWrapper.eq("password",loginDTO.getPassword());
        AdminDAO adminDAO = adminMapper.selectOne(queryWrapper);
        if(adminDAO==null)
        {
            return -1;
        }
        return adminDAO.getId();
    }
}
